#!/bin/bash
source /etc/profile
if [ -n "$1" ] ;then
do_date=$1
else
do_date=`date -d "-6 day" +%F`
fi

sql="
with tmp as(
select uid 
from (select uid, dt,
date_sub(dt, row_number() over (partition by uid
order by dt)) gid
from dws.dws_member_start_day
where dt >= '$do_date') t1
group by uid, gid
having active_cnt >= 3
）
insert overwrite table ads.ads_member_active_count_day3
partition(dt='$do_date')
select sum(uid) as day_count from tmp;
"
hive -e "$sql"